namespace Warehouse

open System
open System.Collections.ObjectModel
open FSharp.Windows

[<AbstractClass>]
type OfferByProductModel() = 
    inherit EntityModel<DataModel.OfferProduct>()

    let mutable product : DataModel.Product = null
    member this.Product with get() = product and set value = product <- value

    member this.Title = product.Title()
    member this.IsLitrSize = product.IsLitrSize()
    abstract Include : bool with get, set
    abstract Quantity : int with get, set
    member this.ShopCost = product.ShopCost
    abstract Commission : decimal with get, set
    abstract Price : decimal with get, set

    override this.Init() = 
        this.Include <- true
        this.Quantity <- this.Entity.Quantity
        this.Commission <- this.Entity.Commission

    override this.Flush() = 
        this.Entity.Product <- product
        this.Entity.Quantity <- this.Quantity
        this.Entity.Commission <- this.Commission

    override this.Compute() =
        this.Price <- this.ShopCost * (1M + this.Commission/100M)

[<AbstractClass>]
type OfferByBrandModel() = 
    inherit Model()

    let mutable brand : DataModel.Brand = null
    member this.Brand with get() = brand and set value = brand <- value

    abstract IncludeAllProducts : bool with get, set
    abstract RegularPct : decimal with get, set
    abstract LitrSizePct : decimal with get, set

    abstract Products : OfferByProductModel[] with get, set

[<AbstractClass>]
type OfferDetailsModel() = 
    inherit EntityModel<DataModel.Offer>()

    abstract Id : int with get, set
    abstract Date : DateTime with get, set
    abstract ByBrand : OfferByBrandModel ObservableCollection with get, set
    abstract SelectedBrand : OfferByBrandModel with get, set

    override this.Init() = 
        this.Id <- this.Entity.Id
        this.Date <- this.Entity.Date

    override this.Flush() = 
        this.Entity.Date <- this.Date

[<AbstractClass>]
type OfferModel() = 
    inherit Model()

    abstract ClientLookUp : DataModel.Client seq with get, set
    abstract SelectedClient : DataModel.Client with get, set

    abstract Items : OfferDetailsModel ObservableCollection with get, set
    abstract SelectedOffer : OfferDetailsModel with get, set
    
    abstract UpcNoteLookUp : DataModel.UpcNote seq with get, set

    